package com.wbl.app.base

import androidx.lifecycle.ViewModel

class MainViewModel:ViewModel() {
    fun longestConsecutive(nums: IntArray): Int {
        val set = HashSet<Int>()
        for(i in nums.indices){
            set.add(i)
        }
        var result = 0
        for(num in set){
            if(set.contains(num-1)){
                continue
            }
            var length = 0
            var tempNum = num
            while(set.contains(tempNum+1)){
                length++
                tempNum++
            }
            result = if(result>length)result else length
        }
        return result
    }
}